<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="教学任务名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'name', validatorRules.name]" placeholder="请输入教学任务名称"></a-input>
        </a-form-item>
        <a-form-item label="教学计划ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jxjhid', validatorRules.jxjhid]" placeholder="请输入教学计划ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="院系ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'falid', validatorRules.falid]" placeholder="请输入院系ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="专业ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'specid', validatorRules.specid]" placeholder="请输入专业ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="年级ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'gradeid', validatorRules.gradeid]" placeholder="请输入年级ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="执行学期ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'semid', validatorRules.semid]" placeholder="请输入执行学期ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="学制ID（根据课程、学期，确定教学计划明细，获取学制ID）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'xzid', validatorRules.xzid]" placeholder="请输入学制ID（根据课程、学期，确定教学计划明细，获取学制ID）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="课程ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'kcid', validatorRules.kcid]" placeholder="请输入课程ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教研组ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jyzid', validatorRules.jyzid]" placeholder="请输入教研组ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="考试形式ID（从数据字典中获取考试形式的值 1=考试，2=考查）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'ksxsid', validatorRules.ksxsid]" placeholder="请输入考试形式ID（从数据字典中获取考试形式的值 1=考试，2=考查）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="选课人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'xkrs', validatorRules.xkrs]" placeholder="请输入选课人数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="是否核心课程：0=否，1=是" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'sfhxkc', validatorRules.sfhxkc]" placeholder="请输入是否核心课程：0=否，1=是" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="课程分类码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'kcflm', validatorRules.kcflm]" placeholder="请输入课程分类码"></a-input>
        </a-form-item>
        <a-form-item label="课程属性码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'kcsxm', validatorRules.kcsxm]" placeholder="请输入课程属性码"></a-input>
        </a-form-item>
        <a-form-item label="课程性质：数据字典ID（专业课=3，学科基础课=2，公共基础课=1）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'kcxz', validatorRules.kcxz]" placeholder="请输入课程性质：数据字典ID（专业课=3，学科基础课=2，公共基础课=1）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="课程学分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'kcxf', validatorRules.kcxf]" placeholder="请输入课程学分" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="总学时" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'zxs', validatorRules.zxs]" placeholder="请输入总学时" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="创建人ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'createuserid', validatorRules.createuserid]" placeholder="请输入创建人ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'createtime', validatorRules.createtime]" placeholder="请输入创建时间" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教师的用户ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'teacheruserid', validatorRules.teacheruserid]" placeholder="请输入教师的用户ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教师的用户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'teachername', validatorRules.teachername]" placeholder="请输入教师的用户姓名"></a-input>
        </a-form-item>
        <a-form-item label="是否合班教学（0=否，1=是）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'ismergedclass', validatorRules.ismergedclass]" placeholder="请输入是否合班教学（0=否，1=是）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="行政班IDs，多个id以 , 隔开" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'xzbids', validatorRules.xzbids]" placeholder="请输入行政班IDs，多个id以 , 隔开"></a-input>
        </a-form-item>
        <a-form-item label="教学任务类型 0：必修课 1：选修课" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'type', validatorRules.type]" placeholder="请输入教学任务类型 0：必修课 1：选修课" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教学班ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jxbid', validatorRules.jxbid]" placeholder="请输入教学班ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教室类型Id（场地要求）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jslxid', validatorRules.jslxid]" placeholder="请输入教室类型Id（场地要求）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教材ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jcid', validatorRules.jcid]" placeholder="请输入教材ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="教室ID（根据当前教学班的）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jsid', validatorRules.jsid]" placeholder="请输入教室ID（根据当前教学班的）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="是否确认（0=未确认（不通过），1=已确认(通过),2.待审核），为选修课时就是审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'checkstatus', validatorRules.checkstatus]" placeholder="请输入是否确认（0=未确认（不通过），1=已确认(通过),2.待审核），为选修课时就是审核状态" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="确认人Id(为选修课时就是审核人)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'checkuserid', validatorRules.checkuserid]" placeholder="请输入确认人Id(为选修课时就是审核人)" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="确认时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'checktime', validatorRules.checktime]" placeholder="请输入确认时间" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="不确认的原因 文本ID(为选修课时就是审核不通过原因))" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'checktid', validatorRules.checktid]" placeholder="请输入不确认的原因 文本ID(为选修课时就是审核不通过原因))" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="成绩状态（1=已录入，2=已提交）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'cjstatus', validatorRules.cjstatus]" placeholder="请输入成绩状态（1=已录入，2=已提交）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="终端ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'terminalid', validatorRules.terminalid]" placeholder="请输入终端ID" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="当教师类型普通教师的时候默认一个固定教师" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'fixedjsid', validatorRules.fixedjsid]" placeholder="请输入当教师类型普通教师的时候默认一个固定教师" style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "VeJwJxrwModal",
    components: {
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          name: {rules: [
            {required: true, message: '请输入教学任务名称!'},
          ]},
          jxjhid: {rules: [
          ]},
          falid: {rules: [
            {required: true, message: '请输入院系ID!'},
          ]},
          specid: {rules: [
            {required: true, message: '请输入专业ID!'},
          ]},
          gradeid: {rules: [
            {required: true, message: '请输入年级ID!'},
          ]},
          semid: {rules: [
            {required: true, message: '请输入执行学期ID!'},
          ]},
          xzid: {rules: [
          ]},
          kcid: {rules: [
            {required: true, message: '请输入课程ID!'},
          ]},
          jyzid: {rules: [
          ]},
          ksxsid: {rules: [
            {required: true, message: '请输入考试形式ID（从数据字典中获取考试形式的值 1=考试，2=考查）!'},
          ]},
          xkrs: {rules: [
            {required: true, message: '请输入选课人数!'},
          ]},
          sfhxkc: {rules: [
            {required: true, message: '请输入是否核心课程：0=否，1=是!'},
          ]},
          kcflm: {rules: [
            {required: true, message: '请输入课程分类码!'},
          ]},
          kcsxm: {rules: [
            {required: true, message: '请输入课程属性码!'},
          ]},
          kcxz: {rules: [
            {required: true, message: '请输入课程性质：数据字典ID（专业课=3，学科基础课=2，公共基础课=1）!'},
          ]},
          kcxf: {rules: [
            {required: true, message: '请输入课程学分!'},
          ]},
          zxs: {rules: [
            {required: true, message: '请输入总学时!'},
          ]},
          createuserid: {rules: [
            {required: true, message: '请输入创建人ID!'},
          ]},
          createtime: {rules: [
            {required: true, message: '请输入创建时间!'},
          ]},
          teacheruserid: {rules: [
            {required: true, message: '请输入教师的用户ID!'},
          ]},
          teachername: {rules: [
            {required: true, message: '请输入教师的用户姓名!'},
          ]},
          ismergedclass: {rules: [
            {required: true, message: '请输入是否合班教学（0=否，1=是）!'},
          ]},
          xzbids: {rules: [
          ]},
          type: {rules: [
            {required: true, message: '请输入教学任务类型 0：必修课 1：选修课!'},
          ]},
          jxbid: {rules: [
            {required: true, message: '请输入教学班ID!'},
          ]},
          jslxid: {rules: [
            {required: true, message: '请输入教室类型Id（场地要求）!'},
          ]},
          jcid: {rules: [
            {required: true, message: '请输入教材ID!'},
          ]},
          jsid: {rules: [
            {required: true, message: '请输入教室ID（根据当前教学班的）!'},
          ]},
          checkstatus: {rules: [
            {required: true, message: '请输入是否确认（0=未确认（不通过），1=已确认(通过),2.待审核），为选修课时就是审核状态!'},
          ]},
          checkuserid: {rules: [
            {required: true, message: '请输入确认人Id(为选修课时就是审核人)!'},
          ]},
          checktime: {rules: [
            {required: true, message: '请输入确认时间!'},
          ]},
          checktid: {rules: [
            {required: true, message: '请输入不确认的原因 文本ID(为选修课时就是审核不通过原因))!'},
          ]},
          cjstatus: {rules: [
          ]},
          terminalid: {rules: [
            {required: true, message: '请输入终端ID!'},
          ]},
          fixedjsid: {rules: [
          ]},
        },
        url: {
          add: "/jxrw/veJwJxrw/add",
          edit: "/jxrw/veJwJxrw/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','jxjhid','falid','specid','gradeid','semid','xzid','kcid','jyzid','ksxsid','xkrs','sfhxkc','kcflm','kcsxm','kcxz','kcxf','zxs','createuserid','createtime','teacheruserid','teachername','ismergedclass','xzbids','type','jxbid','jslxid','jcid','jsid','checkstatus','checkuserid','checktime','checktid','cjstatus','terminalid','fixedjsid'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                that.close();
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'name','jxjhid','falid','specid','gradeid','semid','xzid','kcid','jyzid','ksxsid','xkrs','sfhxkc','kcflm','kcsxm','kcxz','kcxf','zxs','createuserid','createtime','teacheruserid','teachername','ismergedclass','xzbids','type','jxbid','jslxid','jcid','jsid','checkstatus','checkuserid','checktime','checktid','cjstatus','terminalid','fixedjsid'))
      }

    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>